package com.gengzp.common.enums;

import com.gengzp.common.exception.BusinessException;
import lombok.Getter;

import java.util.Objects;

/**
 * @ClassName ClientTypeEnum
 * @Description 客户端类型枚举类
 * @Author gengzp
 * @Date 2025/9/8 15:30
 */
@Getter
public enum ClientTypeEnum {

    PC(0, "pc端"),
    MOBILE(1, "移动端"),
    ;

    private final int code;
    private final String value;

    ClientTypeEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    /**
     * 根据编码获取枚举值
     */
    public static String getValueByCode(int code) {
        for (ClientTypeEnum v : ClientTypeEnum.values()) {
            if (Objects.equals(v.getCode(), code)) {
                return v.getValue();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", ClientTypeEnum.class, code));
    }

    /**
     * 根据枚举值获取编码
     */
    public static int getCodeByValue(String value) {
        for (ClientTypeEnum v : ClientTypeEnum.values()) {
            if (Objects.equals(v.getValue(), value)) {
                return v.getCode();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", ClientTypeEnum.class, value));
    }

}
